package com.filldream.fastboot.common.okutil.cls.dto;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.filldream.fastboot.common.okutil.stock.cf.comment.dto.CfComment;
import com.filldream.fastboot.common.okutil.stock.cf.comment.dto.CfCommentPostUser;
import com.filldream.fastboot.common.util.JsonUtil;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.apache.commons.lang3.StringUtils;
import java.util.*;

@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class ClsNewsSimpleItem {

    @TableId(value = "db_id", type = IdType.AUTO)
    @ApiModelProperty(value = "数据库ID")
    private Long dbId;

    @ApiModelProperty(value = "文章ID")
    private String id;

    @ApiModelProperty(value = "文章标题")
    private String title;

    @ApiModelProperty(value = "文章地址")
    private String linkUrl;

    @ApiModelProperty(value = "配图")
    private String img;

    @ApiModelProperty(value = "是否置顶")
    private Boolean isTop = false;

    private Integer sourceType;

    private String sendOwner;

    private String mediaName;

    private String brief;

    private Date publishTime;

    public List<Map<String,Object>> initFeiShu(int index){
        Map<String, Object> map = new HashMap<>();
        map.put("tag", "a");
        map.put("text",index + "、" + title);
        map.put("href", linkUrl);
        return Collections.singletonList(map);
    }

    public List<String> getSendOwnerList() {
        if(StringUtils.isBlank(sendOwner)){
            return new LinkedList<>();
        }
        return JsonUtil.fromJosnArray(  sendOwner, String.class);
    }

    public ClsNewsSimpleItem toClsNewsSimpleItem(){
        ClsNewsSimpleItem item = new ClsNewsSimpleItem();
        item.setTitle( title );
        item.setIsTop(false);
        item.setLinkUrl(linkUrl);
        return item;
    }

    public CfComment toCfComment(){
        CfComment cfComment = new CfComment();
        cfComment.setChannelType(4);
        cfComment.setPost_id( Long.valueOf(id) );
        cfComment.setTheme( "" );
        cfComment.setPost_title("");
        cfComment.setPost_content( brief );
        cfComment.setPost_pic_url( new ArrayList<>() );
        cfComment.setPost_publish_time( DateUtil.date(publishTime).toString("yyyy-MM-dd HH:mm:ss") );
        cfComment.setStockName(title);
        cfComment.setReply_list(new ArrayList<>());
        CfCommentPostUser cfCommentPostUser = new CfCommentPostUser();
        cfCommentPostUser.setUser_age(null);
        cfCommentPostUser.setUser_nickname( mediaName );
        cfComment.setPost_user( cfCommentPostUser);
        return cfComment;
    }

}
